Page({
  data:{
    carList:[],
    proC:"",
    cityC:"",
    proA:"",
    cityA:"",
    proIndex:"",
    cityIndex:"",
    isLogin:false,
    area_name:"",
  },
  onLoad:function(){
    if(!wx.getStorageSync("user_id")){
      this.data.isLogin=true;
      this.setData({
        isLogin:true
      })
    }
    var cityID="";
    if(wx.getStorageSync("city_id")){
      cityID=wx.getStorageSync("city_id");
    }
    console.log(cityID)
    var self=this;
    wx.showLoading();
    wx.request({
      url:"https://wx.ichelaba.com/htapi/index.php/store/product_list",
      data:{
        area_id:cityID
      },
      method:"GET",
      success:function(res){
        console.log(res);
        self.setData({
          carList:res.data.product_list,
          area_name:res.data.area_name
        })
        wx.setStorageSync("city_id",res.data.area_id);
        wx.setStorageSync("city_name",res.data.area_name);
        // wx.request({
        //   url:"https://wx.ichelaba.com/htapi/index.php/user/address/add",
        //   data:{
        //     user_id:wx.getStorageSync("user_id")
        //   },
        //   method:"GET",
        //   success:function(res){
            self.data.proC=res.data.province_list;
            var proA=[];
            for(var i=0;i<res.data.province_list.length;i++){
              proA.push(res.data.province_list[i].district_name);
            }
            self.setData({
              proIndex:0,
              proA:proA
            })
            wx.request({
              url:"https://wx.ichelaba.com/htapi/index.php/user/address/getCity",
              data:{
                user_id:wx.getStorageSync("user_id"),
                pid:self.data.proC[0].district_id
              },
              method:"GET",
              success:function(res){
                self.data.cityC=res.data.list;
                var cityA=[];
                for(var i=0;i<res.data.list.length;i++){
                  cityA.push(res.data.list[i].district_name);
                }
                self.setData({
                  cityIndex:0,
                  cityA:cityA
                })
                wx.hideLoading();
              }
            })
        //   }
        // })
      }
    })
  },
  columnchange_FN:function(e){
    var self=this;
    if(e.detail.column==0){
      self.setData({
        proIndex:e.detail.value
      })
      wx.request({
        url:"https://wx.ichelaba.com/htapi/index.php/user/address/getCity",
        data:{
          user_id:wx.getStorageSync("user_id"),
          pid:self.data.proC[e.detail.value].district_id
        },
        method:"GET",
        success:function(res){
          self.data.cityC=res.data.list;
          var cityA=[];
          for(var i=0;i<res.data.list.length;i++){
            cityA.push(res.data.list[i].district_name);
          }
          self.setData({
            cityIndex:0,
            cityA:cityA
          })
        }
      })
    }
  },
  change_FN:function(e){
    var thisIndex="";
    if(e.detail.value[1]==null){
      thisIndex=0;
    }else{
      thisIndex=e.detail.value[1]
    }
    wx.setStorageSync("city_id",this.data.cityC[thisIndex].district_id);
    wx.setStorageSync("city_name",this.data.cityC[thisIndex].district_name);
    wx.reLaunch({
      url:"/pages/carList/carList"
    })
  }
})